﻿using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Integration;

namespace Headsight.BPMN2WF.ConversionWizard
{
    public partial class ChooseBPMNStep : Form
    {
        private readonly ElementHost _ctrlHost;
        private readonly BPMN2WFConverter _bpmn2WFConverter;
        
        public string BpmnFileContent { get; set; }
        public string WorkflowXamlContent { get; set; }
        
        public ChooseBPMNStep()
        {
            InitializeComponent();

            FormBorderStyle = FormBorderStyle.FixedDialog;

            _ctrlHost = new ElementHost { Dock = DockStyle.Fill };
            panelDesigner.Controls.Add(_ctrlHost);

            _bpmn2WFConverter = new BPMN2WFConverter();
            _bpmn2WFConverter.PropertyChanged += _bpmn2wfConverter_PropertyChanged;

            _ctrlHost.Child = _bpmn2WFConverter;
        }

        private void _bpmn2wfConverter_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "WorkflowXamlContent")
            {
                WorkflowXamlContent = _bpmn2WFConverter.WorkflowXamlContent;
                //Dispose();
            }
            if (e.PropertyName == "CloseMe")
            {
                if (_bpmn2WFConverter.CloseMe)
                    Dispose();
            }
        }
    }
}
